package org.jxht.web.api;

import org.jxht.dto.MajProDto;
import org.jxht.dto.MajorDto;
import org.jxht.dto.ProfessionDto;
import org.jxht.service.MajProServie;
import org.jxht.service.ProfessionServie;
import org.jxht.util.GsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by huang on 2017/3/20 0020.
 */
@Controller
@RequestMapping("JxhtWeb/ProfessionController")
public class ProfessionController {

    @Autowired
    private ProfessionServie professionServie;

    @Autowired
    private MajProServie majProServie;

    /**
     * 添加专业
     * @param reuqestId 执行该功能的用户Id
     * @param requestJson Json字符串
     * @return String
     */
    @RequestMapping(value = "/{reuqestId}/addProfession")
    public String addProfession(@PathVariable(value = "reuqestId")int reuqestId,
                                 @RequestParam(value = "requestJson")String requestJson){
        List<ProfessionDto> dtos = GsonUtil.parseJsonArrayWithGson(requestJson,ProfessionDto.class);
        for(ProfessionDto dto:dtos){
            professionServie.insertProfessionService(dto);
        }
        return "SUCCESS";
    }

    /**
     * 删除专业
     * @param professionId 专业Id
     * @return String
     */
    @RequestMapping(value = "/{professionId}/changeTeaCouRecord")
    public String changeTeaCouRecord(@PathVariable(value = "professionId")int professionId){
        if(professionId<1000)
            professionServie.deleteProfessionService(new ProfessionDto("0"+Integer.toString(professionId)));
        else
            professionServie.deleteProfessionService(new ProfessionDto(Integer.toString(professionId)));
        return "SUCCESS";
    }

    /**
     * 获取专业信息
     * @param requestId 获取用户Id
     * @param requestJson 条件(majId, proId, stuProId)
     * @return MajorDto
     */
    @RequestMapping(value = "/{requestId}/getMajorInfoSingle",method = RequestMethod.GET)
    @ResponseBody
    public List<MajProDto> getProfessionInfoSingle(@PathVariable(value = "requestId")int requestId,
                                                   @RequestParam(value = "requestJson") String requestJson){
        MajProDto dto = GsonUtil.parseJsonWithGson(requestJson,MajProDto.class);
        return professionServie.queryProfessionService(dto);
    }
}
